
using System;

namespace Framework {
    public abstract class Singleton<T> where T : class, new()
    {
        private static T s_Instance;
        public static T Instance
        {
            get
            {
                if (s_Instance == null)
                {
                    s_Instance = Activator.CreateInstance<T>();
                    if (s_Instance != null)
                    {
                        (s_Instance as Singleton<T>).Init();
                    }
                }

                return s_Instance;
            }
        }

        public static void Release()
        {
            if (s_Instance != null)
            {
                (s_Instance as Singleton<T>).Dispose();
                s_Instance = (T)((object)null);
            }
        }

        public virtual void Init() {}

        public virtual void Dispose() {}
    }
}